package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.HeadshipDTO;
import cn.com.blueInfo.bpm.person.response.HeadshipVO;
import cn.com.blueInfo.bpm.person.service.HeadshipService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 职务信息表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "职务信息 接口")
@RestController
@RequestMapping("/person/headship")
public class HeadshipController extends BaseController {

    @Autowired
    private HeadshipService headshipService;

    /**
     * 新建职务信息
     * @param headshipDTO 职务信息参数
     * @return ResultInfo
     */
    @Operation(summary = "新增职务信息")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createHeadship(
            @Validated({Create.class, Default.class}) @RequestBody HeadshipDTO headshipDTO) {
        return headshipService.addHeadship(headshipDTO);
    }

    /**
     * 批量新建职务信息
     * @param headshipDTOList 职务信息参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建职务信息")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateHeadship(
            @Validated({Create.class, Default.class}) @RequestBody List<HeadshipDTO> headshipDTOList) {
        return headshipService.batchAddHeadship(headshipDTOList);
    }

    /**
     * 根据ID删除职务信息
     * @param headshipId 职务信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除职务信息")
    @DeleteMapping("/removeInfo/{headshipId}")
    public ResultInfo<Integer> deleteHeadshipById(
            @Parameter(name = "ID") @PathVariable Long headshipId) {
        return headshipService.removeHeadship(headshipId);
    }

    /**
     * 批量根据ID删除职务信息
     * @param headshipIdList 职务信息ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除职务信息")
    @DeleteMapping("/removeInfoList/{headshipIdList}")
    public ResultInfo<Integer> batchDeleteHeadshipById(
            @Parameter(name = "ID") @PathVariable List<Long> headshipIdList) {
        return headshipService.batchRemoveHeadship(headshipIdList);
    }

    /**
     * 根据ID全量更新职务信息
     * @param headshipId 职务信息ID
     * @param headshipDTO 职务信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新职务信息")
    @PutMapping("/modifyInfo/{headshipId}")
    public ResultInfo<Integer> updateHeadshipFull(
            @Parameter(name = "ID") @PathVariable Long headshipId,
            @Validated({Update.class, Default.class}) @RequestBody HeadshipDTO headshipDTO) {
        validateUpdateId(headshipId, headshipDTO.getId());
        return headshipService.modifyHeadship(headshipDTO);
    }

    /**
     * 根据ID部分更新职务信息
     * @param headshipId 职务信息ID
     * @param headshipUpdatePartialDTO 职务信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新职务信息")
    @PatchMapping("/modifyPartialInfo/{headshipId}")
    public ResultInfo<Integer> updateHeadshipPartial(
            @Parameter(name = "ID") @PathVariable Long headshipId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            HeadshipDTO.UpdatePartialDTO headshipUpdatePartialDTO) {
        validateUpdateId(headshipId, headshipUpdatePartialDTO.getId());
        return headshipService.modifyHeadshipPartial(headshipUpdatePartialDTO);
    }

    /**
     * 根据ID查询职务信息
     * @param headshipId 职务信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询职务信息")
    @GetMapping("/getInfo/{headshipId}")
    public ResultInfo<HeadshipVO> getHeadshipById(
            @Parameter(name = "ID") @PathVariable Long headshipId) {
        return headshipService.queryHeadshipById(headshipId);
    }

    /**
     * 分页查询职务信息
     * @param headshipQueryDTO 职务信息参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询职务信息")
    @GetMapping("/getInfos")
    public ResultInfo<Page<HeadshipVO>> getHeadshipPage(
            @Validated HeadshipDTO.QueryDTO headshipQueryDTO) {
        return headshipService.queryHeadshipPage(headshipQueryDTO);
    }

    /**
     * 根据条件查询职务信息
     * @param headshipQueryDTO 职务信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询职务信息")
    @GetMapping("/getInfoList")
    public ResultInfo<List<HeadshipVO>> getHeadshipList(
            @Validated HeadshipDTO.QueryDTO headshipQueryDTO) {
        return headshipService.queryHeadshipList(headshipQueryDTO);
    }

}
